<template>
<view class="content">
  <view class="title">
    您将会把以下单元的临时开门权限共享给你的好友，临时开门权限时效为{{time}}{{type}}，超过时效时间您的好友则无法开门
  </view>
  <view class="home " style="margin-top:10px">
    <block v-for="(item, index) in list" :key="index">
      <view class="bg_f" v-if="item.floor_id && item.floor_id==-1">{{item.floor_layer}} {{item.floor_name}} ({{item.door_name}}) </view>
      <view class="bg_f" v-else>{{item.floor_layer}} {{item.floor_name}} </view>
    </block>
  </view>
  <view class=" hidden home mg_20">
    <text class="desc ">分享开门权限给访客</text>
    <view style="padding:20px;">
      <view class="weui-media-box__title ">
        <view class="rel">

          <image src="/static/images/weiixin.png" class="image"></image>
          <text>微信好友</text>
          <button type="primary" open-type="share" class="shareGroup"></button>


        </view>

      </view>
    </view>

  </view>
</view>
</template>

"<script>
var app = getApp();
var common = require('../../utils/common.js');

export default {
  data() {
    return {
      desc: '',
      img: '',
      list: [],
      type: '',
      time: 0,
      home: ''
    };
  },

  onShareAppMessage: function () {
    var that = this;
	let pageLink = '/pages/plat_menu/index?door_share_id=' + that.door_share_id + '&redirect=1'
	pageLink = common.addShareParam(pageLink)
    return {
      title: '我送您一个时效为' + that.time + that.type + '的【' + that.home + '】小区临时开门权限',
      desc: that.desc,
      imageUrl: that.img,
      path: pageLink,
      success: function (res) {
        var shareTickets = res.shareTickets;

        if (shareTickets.length == 0) {
          return false;
        }

        wx.getShareInfo({
          shareTicket: shareTickets[0],
          success: function (res) {
            var encryptedData = res.encryptedData;
            var iv = res.iv;
          }
        });
      }
    };
  },
  onUnload: function () {// 页面关闭
  },
  onHide: function () {// 页面隐藏
  },
  onShow: function () {},
  onLoad: function (opt) {
    var that = this;
    wx.showShareMenu({
      withShareTicket: true
    });
    this.setData({
      desc: opt.desc,
      img: opt.img,
      door_share_id: opt.door_share_id
    });
    common.post('House&a=house_village_door_share_info', {
      door_share_id: opt.door_share_id
    }, function (res) {
      console.log('时间限制', res.share_time_type);
      console.log(res);
      that.setData({
        list: res.share_info,
        time: res.share_time_length,
        home: res.village_name,
        type: res.share_time_type == 0 ? '分钟' : res.share_time_type == 1 ? '小时' : '天'
      });
    });
  },
  components: {},
  props: {},
  methods: {
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
.content{padding:20px;font-size:16px;text-align:center;color:#333}
.home{padding:0px 20px}
.bg_f{background:#fff}
.home>view{padding: 10px;margin-bottom:10px;text-align:left}
.title{margin-bottom:10px;line-height:30px;font-size:14px;  }
.hidden{overflow:hidden}
.desc{position:relative}
.mg_20{margin:30px 0px 20px 0px;  }
.rel{position:relative}
.desc:after{position:absolute;content: '';height:1px ;border-top:1px solid #ddd;top:50%;right:105%;width: 100%;}
.desc:before{position:absolute;content: '';height:1px ;border-top:1px solid #ddd;top:50%;left:105%;width: 100%;}
.image{width:35px;height:35px;display:block;margin:auto}
.please{width:50px;position:relative}
 button{position:absolute;  top:0;  left:33%;  width:37%;  height:100%;  z-index:10;  opacity:0;  background-color:transparent !important;display:inline !important;color:#000 !important;font-size:16px !important;line-height:normal !important;}
 button:after,.please button:before{content:none !important;}
.weui-media-box__title{text-align:center}
</style>